<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>安装 | Vue.js</title>
    <meta name="generator" content="VuePress 1.8.2">
    <link href="https://fonts.googleapis.com/css?family=Inter:300,400,500,600|Open+Sans:400,600;display=swap" rel="stylesheet">
    <link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
    <link rel="icon" href="/logo.png">
    <link rel="manifest" href="/manifest.json">
    <link rel="apple-touch-icon" href="/images/icons/apple-icon-152x152.png">
    <script src="https://player.youku.com/iframeapi"></script>
    <meta name="description" content="Vue.js - The 渐进式 JavaScript 框架">
    <meta name="theme-color" content="#3eaf7c">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="msapplication-TileImage" content="/images/icons/ms-icon-144x144.png">
    <meta name="msapplication-TileColor" content="#000000">
    
    <link rel="preload" href="/assets/css/0.styles.9bf58a16.css" as="style"><link rel="preload" href="/assets/js/app.9f011487.js" as="script"><link rel="preload" href="/assets/js/11.bea13863.js" as="script"><link rel="preload" href="/assets/js/116.5836841c.js" as="script"><link rel="preload" href="/assets/js/25.3a155505.js" as="script"><link rel="preload" href="/assets/js/23.f23a1976.js" as="script"><link rel="prefetch" href="/assets/js/1.98516ad1.js"><link rel="prefetch" href="/assets/js/100.94330a5d.js"><link rel="prefetch" href="/assets/js/101.560a6b49.js"><link rel="prefetch" href="/assets/js/102.f12c4d91.js"><link rel="prefetch" href="/assets/js/103.be709996.js"><link rel="prefetch" href="/assets/js/104.49fdebb1.js"><link rel="prefetch" href="/assets/js/105.df17d42d.js"><link rel="prefetch" href="/assets/js/106.fa0a51b7.js"><link rel="prefetch" href="/assets/js/107.392361bf.js"><link rel="prefetch" href="/assets/js/108.af6fc4d6.js"><link rel="prefetch" href="/assets/js/109.18bcf602.js"><link rel="prefetch" href="/assets/js/110.052b8c4c.js"><link rel="prefetch" href="/assets/js/111.528533a3.js"><link rel="prefetch" href="/assets/js/112.28359168.js"><link rel="prefetch" href="/assets/js/113.190e7aff.js"><link rel="prefetch" href="/assets/js/114.dddc32bb.js"><link rel="prefetch" href="/assets/js/115.7924a11d.js"><link rel="prefetch" href="/assets/js/117.1e3523ad.js"><link rel="prefetch" href="/assets/js/118.fda02ea3.js"><link rel="prefetch" href="/assets/js/119.c56ed999.js"><link rel="prefetch" href="/assets/js/12.11fdef37.js"><link rel="prefetch" href="/assets/js/120.14653326.js"><link rel="prefetch" href="/assets/js/121.5bdc69d1.js"><link rel="prefetch" href="/assets/js/122.ea246bef.js"><link rel="prefetch" href="/assets/js/123.1a041b0d.js"><link rel="prefetch" href="/assets/js/124.4849397b.js"><link rel="prefetch" href="/assets/js/125.f8a4d9a1.js"><link rel="prefetch" href="/assets/js/126.e6f8c88f.js"><link rel="prefetch" href="/assets/js/127.bb0d0c14.js"><link rel="prefetch" href="/assets/js/128.6fcdf065.js"><link rel="prefetch" href="/assets/js/129.d37419cf.js"><link rel="prefetch" href="/assets/js/13.84b5a427.js"><link rel="prefetch" href="/assets/js/130.2ff76428.js"><link rel="prefetch" href="/assets/js/131.dbd74031.js"><link rel="prefetch" href="/assets/js/132.b4ca1a54.js"><link rel="prefetch" href="/assets/js/133.95a81c57.js"><link rel="prefetch" href="/assets/js/134.da6a25f1.js"><link rel="prefetch" href="/assets/js/135.46cd4ce4.js"><link rel="prefetch" href="/assets/js/136.c908c444.js"><link rel="prefetch" href="/assets/js/137.838c736d.js"><link rel="prefetch" href="/assets/js/138.5f56ac41.js"><link rel="prefetch" href="/assets/js/139.2d3218e7.js"><link rel="prefetch" href="/assets/js/14.ccde2ff7.js"><link rel="prefetch" href="/assets/js/140.73a6c08b.js"><link rel="prefetch" href="/assets/js/141.e6e97fa2.js"><link rel="prefetch" href="/assets/js/142.78b66660.js"><link rel="prefetch" href="/assets/js/143.18a5f522.js"><link rel="prefetch" href="/assets/js/144.007967ab.js"><link rel="prefetch" href="/assets/js/145.69c6c622.js"><link rel="prefetch" href="/assets/js/146.5eb14458.js"><link rel="prefetch" href="/assets/js/147.01b7b88c.js"><link rel="prefetch" href="/assets/js/148.c4464ffa.js"><link rel="prefetch" href="/assets/js/149.66883751.js"><link rel="prefetch" href="/assets/js/15.6957b547.js"><link rel="prefetch" href="/assets/js/150.03ccd0c3.js"><link rel="prefetch" href="/assets/js/151.5cb25376.js"><link rel="prefetch" href="/assets/js/152.51fa843b.js"><link rel="prefetch" href="/assets/js/153.c280bbfc.js"><link rel="prefetch" href="/assets/js/154.3c1208bb.js"><link rel="prefetch" href="/assets/js/155.f2bec114.js"><link rel="prefetch" href="/assets/js/156.9d563e5f.js"><link rel="prefetch" href="/assets/js/157.09a62483.js"><link rel="prefetch" href="/assets/js/158.e8ee954d.js"><link rel="prefetch" href="/assets/js/159.806c0da5.js"><link rel="prefetch" href="/assets/js/16.1c3a9fe2.js"><link rel="prefetch" href="/assets/js/160.70fe7ee3.js"><link rel="prefetch" href="/assets/js/161.7b67e86f.js"><link rel="prefetch" href="/assets/js/162.d2cb71f8.js"><link rel="prefetch" href="/assets/js/163.c2f8c96a.js"><link rel="prefetch" href="/assets/js/164.c0ce5d22.js"><link rel="prefetch" href="/assets/js/165.dd31fc10.js"><link rel="prefetch" href="/assets/js/166.861df1bd.js"><link rel="prefetch" href="/assets/js/167.8cade3be.js"><link rel="prefetch" href="/assets/js/168.d384c54a.js"><link rel="prefetch" href="/assets/js/169.266b17c8.js"><link rel="prefetch" href="/assets/js/17.13ae2912.js"><link rel="prefetch" href="/assets/js/170.8da5cca1.js"><link rel="prefetch" href="/assets/js/171.59233d62.js"><link rel="prefetch" href="/assets/js/172.e2ff7db9.js"><link rel="prefetch" href="/assets/js/173.4fae5fdf.js"><link rel="prefetch" href="/assets/js/174.25d65654.js"><link rel="prefetch" href="/assets/js/175.0fd8e932.js"><link rel="prefetch" href="/assets/js/176.afbb20d7.js"><link rel="prefetch" href="/assets/js/177.3fce4ef4.js"><link rel="prefetch" href="/assets/js/178.a69eab8f.js"><link rel="prefetch" href="/assets/js/179.b9c69246.js"><link rel="prefetch" href="/assets/js/18.2176f64f.js"><link rel="prefetch" href="/assets/js/180.80eaf61f.js"><link rel="prefetch" href="/assets/js/181.8c9ea68f.js"><link rel="prefetch" href="/assets/js/182.363237b2.js"><link rel="prefetch" href="/assets/js/183.1bcce34d.js"><link rel="prefetch" href="/assets/js/184.63965c38.js"><link rel="prefetch" href="/assets/js/185.145d17f7.js"><link rel="prefetch" href="/assets/js/186.01c28041.js"><link rel="prefetch" href="/assets/js/187.651fc5e1.js"><link rel="prefetch" href="/assets/js/188.371a53d8.js"><link rel="prefetch" href="/assets/js/189.21a8c4f3.js"><link rel="prefetch" href="/assets/js/19.f35e6099.js"><link rel="prefetch" href="/assets/js/2.655ed906.js"><link rel="prefetch" href="/assets/js/20.6a9108db.js"><link rel="prefetch" href="/assets/js/21.b90deaac.js"><link rel="prefetch" href="/assets/js/22.2da4161c.js"><link rel="prefetch" href="/assets/js/24.0f4c4cde.js"><link rel="prefetch" href="/assets/js/26.d7a45b3e.js"><link rel="prefetch" href="/assets/js/27.3c237b85.js"><link rel="prefetch" href="/assets/js/28.1722182e.js"><link rel="prefetch" href="/assets/js/29.158159ee.js"><link rel="prefetch" href="/assets/js/3.9e67029d.js"><link rel="prefetch" href="/assets/js/30.085c3faf.js"><link rel="prefetch" href="/assets/js/31.d95eaf7d.js"><link rel="prefetch" href="/assets/js/32.75be14cd.js"><link rel="prefetch" href="/assets/js/33.b9adbce6.js"><link rel="prefetch" href="/assets/js/34.ef96058c.js"><link rel="prefetch" href="/assets/js/35.f2d110b9.js"><link rel="prefetch" href="/assets/js/36.11e69166.js"><link rel="prefetch" href="/assets/js/37.d51d98ce.js"><link rel="prefetch" href="/assets/js/38.ba303c3e.js"><link rel="prefetch" href="/assets/js/39.7af701c4.js"><link rel="prefetch" href="/assets/js/4.2768033f.js"><link rel="prefetch" href="/assets/js/40.50b39df3.js"><link rel="prefetch" href="/assets/js/41.377521c6.js"><link rel="prefetch" href="/assets/js/42.3b63f9c9.js"><link rel="prefetch" href="/assets/js/43.98898a3b.js"><link rel="prefetch" href="/assets/js/44.29a6e6a2.js"><link rel="prefetch" href="/assets/js/45.7d0883fe.js"><link rel="prefetch" href="/assets/js/46.4e93f7dd.js"><link rel="prefetch" href="/assets/js/47.4c629b92.js"><link rel="prefetch" href="/assets/js/48.f1bf29a9.js"><link rel="prefetch" href="/assets/js/49.a49482a4.js"><link rel="prefetch" href="/assets/js/5.175dbe8f.js"><link rel="prefetch" href="/assets/js/50.dbad5716.js"><link rel="prefetch" href="/assets/js/51.76b7354d.js"><link rel="prefetch" href="/assets/js/52.3a1a9a63.js"><link rel="prefetch" href="/assets/js/53.be592e24.js"><link rel="prefetch" href="/assets/js/54.d97c6e79.js"><link rel="prefetch" href="/assets/js/55.eff64da2.js"><link rel="prefetch" href="/assets/js/56.e3dc0e44.js"><link rel="prefetch" href="/assets/js/57.d7b38bdd.js"><link rel="prefetch" href="/assets/js/58.fdc076c9.js"><link rel="prefetch" href="/assets/js/59.9f11e0ea.js"><link rel="prefetch" href="/assets/js/6.c6369861.js"><link rel="prefetch" href="/assets/js/60.a818862d.js"><link rel="prefetch" href="/assets/js/61.bb9ab96c.js"><link rel="prefetch" href="/assets/js/62.116aefff.js"><link rel="prefetch" href="/assets/js/63.be6c07d0.js"><link rel="prefetch" href="/assets/js/64.0ad95216.js"><link rel="prefetch" href="/assets/js/65.f8749c54.js"><link rel="prefetch" href="/assets/js/66.7680f482.js"><link rel="prefetch" href="/assets/js/67.6fba4d5a.js"><link rel="prefetch" href="/assets/js/68.ed63b04b.js"><link rel="prefetch" href="/assets/js/69.73b3bf13.js"><link rel="prefetch" href="/assets/js/7.cd1985fe.js"><link rel="prefetch" href="/assets/js/70.6e7dc295.js"><link rel="prefetch" href="/assets/js/71.32c17a2a.js"><link rel="prefetch" href="/assets/js/72.ab8b426d.js"><link rel="prefetch" href="/assets/js/73.73838f6c.js"><link rel="prefetch" href="/assets/js/74.c3c5f3e6.js"><link rel="prefetch" href="/assets/js/75.5f63164c.js"><link rel="prefetch" href="/assets/js/76.6071fb5c.js"><link rel="prefetch" href="/assets/js/77.1f274f68.js"><link rel="prefetch" href="/assets/js/78.16d4c50b.js"><link rel="prefetch" href="/assets/js/79.fc2b2e03.js"><link rel="prefetch" href="/assets/js/80.42173ce4.js"><link rel="prefetch" href="/assets/js/81.51405a99.js"><link rel="prefetch" href="/assets/js/82.be2d0e4f.js"><link rel="prefetch" href="/assets/js/83.75b4d2af.js"><link rel="prefetch" href="/assets/js/84.fbaa5717.js"><link rel="prefetch" href="/assets/js/85.60063971.js"><link rel="prefetch" href="/assets/js/86.cf80c75d.js"><link rel="prefetch" href="/assets/js/87.eca6cea7.js"><link rel="prefetch" href="/assets/js/88.3967efe4.js"><link rel="prefetch" href="/assets/js/89.bf83cb8c.js"><link rel="prefetch" href="/assets/js/90.96996b25.js"><link rel="prefetch" href="/assets/js/91.31b5ee41.js"><link rel="prefetch" href="/vue3/assets/js/92.d197feb2.js"><link rel="prefetch" href="/vue3/assets/js/93.b471c7fe.js"><link rel="prefetch" href="/vue3/assets/js/94.b4298707.js"><link rel="prefetch" href="/vue3/assets/js/95.2f91d14f.js"><link rel="prefetch" href="/vue3/assets/js/96.18b64251.js"><link rel="prefetch" href="/vue3/assets/js/97.363729fa.js"><link rel="prefetch" href="/vue3/assets/js/98.cb8f0be4.js"><link rel="prefetch" href="/vue3/assets/js/99.f62cf45d.js"><link rel="prefetch" href="/vue3/assets/js/vendors~docsearch.5cf23a03.js"><link rel="prefetch" href="/vue3/assets/js/vendors~search-page.d14326ff.js">
    <link rel="stylesheet" href="/vue3/assets/css/0.styles.9bf58a16.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><!----> <header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/vue3/" class="home-link router-link-active"><img src="/vue3/logo.png" alt="Vue.js" class="logo"> <span class="site-name can-hide">Vue.js</span></a> <span style="font-size:.9rem;color:#2c3e50;margin-left:20px;">非官方文档，查看官方文档请移步<a href="https://v3.cn.vuejs.org/" target="_blank">这里</a></span> <div class="links"><!----> <nav class="nav-links can-hide"><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="文档菜单" class="dropdown-title"><span class="title">文档</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/vue3/guide/introduction.html" class="nav-link">
  教程
</a></li><li class="dropdown-item"><!----> <a href="/vue3/style-guide/" class="nav-link">
  风格指南
</a></li><li class="dropdown-item"><!----> <a href="/vue3/cookbook/" class="nav-link">
  Cookbook
</a></li><li class="dropdown-item"><!----> <a href="/vue3/examples/markdown.html" class="nav-link">
  示例
</a></li><li class="dropdown-item"><!----> <a href="/vue3/guide/contributing/writing-guide.html" class="nav-link">
  贡献文档
</a></li><li class="dropdown-item"><!----> <a href="/vue3/guide/migration/introduction.html" class="nav-link">
  从 Vue 2 迁移
</a></li></ul></div></div><div class="nav-item"><a href="/vue3/api/" class="nav-link">
  API 参考
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="生态系统" class="dropdown-title"><span class="title">生态系统</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          社区
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/vue3/community/team/" class="nav-link">
  团队
</a></li><li class="dropdown-subitem"><a href="/vue3/community/partners.html" class="nav-link">
  合作伙伴
</a></li><li class="dropdown-subitem"><a href="/vue3/community/join/" class="nav-link">
  加入
</a></li><li class="dropdown-subitem"><a href="/vue3/community/themes/" class="nav-link">
  主题
</a></li></ul></li><li class="dropdown-item"><h4>
          官方项目
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="https://next.router.vuejs.org/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Vue Router
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-subitem"><a href="https://next.vuex.vuejs.org/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Vuex
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-subitem"><a href="https://cli.vuejs.org/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Vue CLI
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-subitem"><a href="https://next.vue-test-utils.vuejs.org/guide/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Vue Test Utils
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-subitem"><a href="https://devtools.vuejs.org" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Devtools
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-subitem"><a href="https://news.vuejs.org/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Weekly news
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-subitem"><a href="https://blog.vuejs.org/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Blog
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="支持 Vue" class="dropdown-title"><span class="title">支持 Vue</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/vue3/support-vuejs/#一次性捐款" class="nav-link">
  一次性捐款
</a></li><li class="dropdown-item"><!----> <a href="/vue3/support-vuejs/#周期性赞助" class="nav-link">
  周期性捐款
</a></li><li class="dropdown-item"><!----> <a href="https://www.smallsticker.com/%E8%B4%B4%E7%BA%B8/vue.html" target="_blank" rel="noopener noreferrer" class="nav-link external">
  贴纸
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-item"><!----> <a href="https://osholic.com/?utm_source=vue&amp;utm_medium=dropdown" target="_blank" rel="noopener noreferrer" class="nav-link external">
  周边
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-item"><!----> <a href="https://vue.threadless.com/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  T-Shirt 商店
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="多语言" class="dropdown-title"><span class="title">多语言</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://v3.vuejs.org/" target="_blank" class="nav-link external">
  English
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-item"><!----> <a href="https://v3.ko.vuejs.org/" target="_blank" class="nav-link external">
  한국어
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-item"><!----> <a href="https://v3.ja.vuejs.org/" target="_blank" class="nav-link external">
  日本語
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-item"><!----> <a href="https://v3.ru.vuejs.org/ru/" target="_blank" class="nav-link external">
  Русский
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-item"><!----> <a href="/vue3/guide/contributing/translations.html#community-translations" class="nav-link">
  更多翻译
</a></li></ul></div></div> <a href="https://github.com/vuejs/docs-next-zh-cn" target="_blank" rel="noopener noreferrer" class="repo-link">
    GitHub
    <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav> <div id="docsearch"></div></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="文档菜单" class="dropdown-title"><span class="title">文档</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/vue3/guide/introduction.html" class="nav-link">
  教程
</a></li><li class="dropdown-item"><!----> <a href="/vue3/style-guide/" class="nav-link">
  风格指南
</a></li><li class="dropdown-item"><!----> <a href="/vue3/cookbook/" class="nav-link">
  Cookbook
</a></li><li class="dropdown-item"><!----> <a href="/vue3/examples/markdown.html" class="nav-link">
  示例
</a></li><li class="dropdown-item"><!----> <a href="/vue3/guide/contributing/writing-guide.html" class="nav-link">
  贡献文档
</a></li><li class="dropdown-item"><!----> <a href="/vue3/guide/migration/introduction.html" class="nav-link">
  从 Vue 2 迁移
</a></li></ul></div></div><div class="nav-item"><a href="/vue3/api/" class="nav-link">
  API 参考
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="生态系统" class="dropdown-title"><span class="title">生态系统</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          社区
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/vue3/community/team/" class="nav-link">
  团队
</a></li><li class="dropdown-subitem"><a href="/vue3/community/partners.html" class="nav-link">
  合作伙伴
</a></li><li class="dropdown-subitem"><a href="/vue3/community/join/" class="nav-link">
  加入
</a></li><li class="dropdown-subitem"><a href="/vue3/community/themes/" class="nav-link">
  主题
</a></li></ul></li><li class="dropdown-item"><h4>
          官方项目
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="https://next.router.vuejs.org/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Vue Router
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-subitem"><a href="https://next.vuex.vuejs.org/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Vuex
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-subitem"><a href="https://cli.vuejs.org/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Vue CLI
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-subitem"><a href="https://next.vue-test-utils.vuejs.org/guide/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Vue Test Utils
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-subitem"><a href="https://devtools.vuejs.org" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Devtools
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-subitem"><a href="https://news.vuejs.org/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Weekly news
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-subitem"><a href="https://blog.vuejs.org/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Blog
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="支持 Vue" class="dropdown-title"><span class="title">支持 Vue</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/vue3/support-vuejs/#一次性捐款" class="nav-link">
  一次性捐款
</a></li><li class="dropdown-item"><!----> <a href="/vue3/support-vuejs/#周期性赞助" class="nav-link">
  周期性捐款
</a></li><li class="dropdown-item"><!----> <a href="https://www.smallsticker.com/%E8%B4%B4%E7%BA%B8/vue.html" target="_blank" rel="noopener noreferrer" class="nav-link external">
  贴纸
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-item"><!----> <a href="https://osholic.com/?utm_source=vue&amp;utm_medium=dropdown" target="_blank" rel="noopener noreferrer" class="nav-link external">
  周边
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-item"><!----> <a href="https://vue.threadless.com/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  T-Shirt 商店
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="多语言" class="dropdown-title"><span class="title">多语言</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://v3.vuejs.org/" target="_blank" class="nav-link external">
  English
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-item"><!----> <a href="https://v3.ko.vuejs.org/" target="_blank" class="nav-link external">
  한국어
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-item"><!----> <a href="https://v3.ja.vuejs.org/" target="_blank" class="nav-link external">
  日本語
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-item"><!----> <a href="https://v3.ru.vuejs.org/ru/" target="_blank" class="nav-link external">
  Русский
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-item"><!----> <a href="/vue3/guide/contributing/translations.html#community-translations" class="nav-link">
  更多翻译
</a></li></ul></div></div> <a href="https://github.com/vuejs/docs-next-zh-cn" target="_blank" rel="noopener noreferrer" class="repo-link">
    GitHub
    <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav>  <ul class="sidebar-links"><li><section class="sidebar-group depth-0"><p class="sidebar-heading open"><span>基础</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/vue3/guide/installation.html" aria-current="page" class="active sidebar-link">安装</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/vue3/guide/installation.html#发布版本说明" class="sidebar-link">发布版本说明</a></li><li class="sidebar-sub-header"><a href="/vue3/guide/installation.html#vue-devtools" class="sidebar-link">Vue Devtools</a></li><li class="sidebar-sub-header"><a href="/vue3/guide/installation.html#cdn" class="sidebar-link">CDN</a></li><li class="sidebar-sub-header"><a href="/vue3/guide/installation.html#下载并自托管" class="sidebar-link">下载并自托管</a></li><li class="sidebar-sub-header"><a href="/vue3/guide/installation.html#npm" class="sidebar-link">npm</a></li><li class="sidebar-sub-header"><a href="/vue3/guide/installation.html#命令行工具-cli" class="sidebar-link">命令行工具 (CLI)</a></li><li class="sidebar-sub-header"><a href="/vue3/guide/installation.html#vite" class="sidebar-link">Vite</a></li><li class="sidebar-sub-header"><a href="/vue3/guide/installation.html#对不同构建版本的解释" class="sidebar-link">对不同构建版本的解释</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/vue3/guide/installation.html#使用-cdn-或没有构建工具" class="sidebar-link">使用 CDN 或没有构建工具</a></li><li class="sidebar-sub-header"><a href="/vue3/guide/installation.html#使用构建工具" class="sidebar-link">使用构建工具</a></li><li class="sidebar-sub-header"><a href="/vue3/guide/installation.html#对于服务端渲染" class="sidebar-link">对于服务端渲染</a></li></ul></li><li class="sidebar-sub-header"><a href="/vue3/guide/installation.html#运行时-编译器-vs-仅运行时" class="sidebar-link">运行时 + 编译器 vs. 仅运行时</a></li></ul></li><li><a href="/vue3/guide/introduction.html" class="sidebar-link">介绍</a></li><li><a href="/vue3/guide/instance.html" class="sidebar-link">应用 &amp; 组件实例</a></li><li><a href="/vue3/guide/template-syntax.html" class="sidebar-link">模板语法</a></li><li><a href="/vue3/guide/data-methods.html" class="sidebar-link">Data Property 和方法</a></li><li><a href="/vue3/guide/computed.html" class="sidebar-link">计算属性和侦听器</a></li><li><a href="/vue3/guide/class-and-style.html" class="sidebar-link">Class 与 Style 绑定</a></li><li><a href="/vue3/guide/conditional.html" class="sidebar-link">条件渲染</a></li><li><a href="/vue3/guide/list.html" class="sidebar-link">列表渲染</a></li><li><a href="/vue3/guide/events.html" class="sidebar-link">事件处理</a></li><li><a href="/vue3/guide/forms.html" class="sidebar-link">表单输入绑定</a></li><li><a href="/vue3/guide/component-basics.html" class="sidebar-link">组件基础</a></li></ul></section></li><li><section class="sidebar-group depth-0"><p class="sidebar-heading"><span>深入组件</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/vue3/guide/component-registration.html" class="sidebar-link">组件注册</a></li><li><a href="/vue3/guide/component-props.html" class="sidebar-link">Props</a></li><li><a href="/vue3/guide/component-attrs.html" class="sidebar-link">非 Prop 的 Attribute</a></li><li><a href="/vue3/guide/component-custom-events.html" class="sidebar-link">自定义事件</a></li><li><a href="/vue3/guide/component-slots.html" class="sidebar-link">插槽</a></li><li><a href="/vue3/guide/component-provide-inject.html" class="sidebar-link">Provide / Inject</a></li><li><a href="/vue3/guide/component-dynamic-async.html" class="sidebar-link">动态组件 &amp; 异步组件</a></li><li><a href="/vue3/guide/component-template-refs.html" class="sidebar-link">模板引用</a></li><li><a href="/vue3/guide/component-edge-cases.html" class="sidebar-link">处理边界情况</a></li></ul></section></li><li><section class="sidebar-group depth-0"><p class="sidebar-heading"><span>过渡 &amp; 动画</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/vue3/guide/transitions-overview.html" class="sidebar-link">过渡 &amp; 动画概述</a></li><li><a href="/vue3/guide/transitions-enterleave.html" class="sidebar-link">进入过渡 &amp; 离开过渡</a></li><li><a href="/vue3/guide/transitions-list.html" class="sidebar-link">列表过渡</a></li><li><a href="/vue3/guide/transitions-state.html" class="sidebar-link">状态过渡</a></li></ul></section></li><li><section class="sidebar-group depth-0"><p class="sidebar-heading"><span>可复用 &amp; 组合</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><section class="sidebar-group collapsable is-sub-group depth-1"><p class="sidebar-heading open"><span>组合式 API</span> <span class="arrow down"></span></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/vue3/guide/composition-api-introduction.html" class="sidebar-link">介绍</a></li><li><a href="/vue3/guide/composition-api-setup.html" class="sidebar-link">Setup</a></li><li><a href="/vue3/guide/composition-api-lifecycle-hooks.html" class="sidebar-link">生命周期钩子</a></li><li><a href="/vue3/guide/composition-api-provide-inject.html" class="sidebar-link">Provide / Inject</a></li><li><a href="/vue3/guide/composition-api-template-refs.html" class="sidebar-link">模板引用</a></li></ul></section></li><li><a href="/vue3/guide/mixins.html" class="sidebar-link">Mixin</a></li><li><a href="/vue3/guide/custom-directive.html" class="sidebar-link">自定义指令</a></li><li><a href="/vue3/guide/teleport.html" class="sidebar-link">Teleport</a></li><li><a href="/vue3/guide/render-function.html" class="sidebar-link">渲染函数</a></li><li><a href="/vue3/guide/plugins.html" class="sidebar-link">插件</a></li></ul></section></li><li><section class="sidebar-group depth-0"><p class="sidebar-heading"><span>高阶指南</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/vue3/guide/web-components.html" class="sidebar-link">Vue 与 Web Components</a></li><li><section class="sidebar-group collapsable is-sub-group depth-1"><p class="sidebar-heading"><span>响应性</span> <span class="arrow right"></span></p> <!----></section></li><li><a href="/vue3/guide/optimizations.html" class="sidebar-link">渲染机制和优化</a></li><li><a href="/vue3/guide/change-detection.html" class="sidebar-link">Vue 2 中更改检测的注意事项</a></li></ul></section></li><li><section class="sidebar-group depth-0"><p class="sidebar-heading"><span>工具</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/vue3/guide/single-file-component.html" class="sidebar-link">单文件组件</a></li><li><a href="/vue3/guide/testing.html" class="sidebar-link">测试</a></li><li><a href="/vue3/guide/typescript-support.html" class="sidebar-link">TypeScript 支持</a></li><li><a href="/vue3/guide/mobile.html" class="sidebar-link">移动端</a></li><li><a href="/vue3/guide/tooling/deployment.html" class="sidebar-link">生产环境部署</a></li></ul></section></li><li><section class="sidebar-group depth-0"><p class="sidebar-heading"><span>规模化</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/vue3/guide/routing.html" class="sidebar-link">路由</a></li><li><a href="/vue3/guide/state-management.html" class="sidebar-link">状态管理</a></li><li><a href="/vue3/guide/ssr.html" class="sidebar-link">服务端渲染</a></li><li><a href="/vue3/guide/security.html" class="sidebar-link">安全</a></li></ul></section></li><li><section class="sidebar-group depth-0"><p class="sidebar-heading"><span>无障碍</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/vue3/guide/a11y-basics.html" class="sidebar-link">基础</a></li><li><a href="/vue3/guide/a11y-semantics.html" class="sidebar-link">语义</a></li><li><a href="/vue3/guide/a11y-standards.html" class="sidebar-link">标准</a></li><li><a href="/vue3/guide/a11y-resources.html" class="sidebar-link">资源</a></li></ul></section></li></ul> </aside> <main class="page"><div class="carbon-ads"></div>  <div class="theme-default-content content__default"><h1 id="安装"><a href="#安装" class="header-anchor">#</a> 安装</h1> <p>Vue.js 设计的初衷就包括可以被渐进式地采用。这意味着它可以根据需求以多种方式集成到一个项目中。</p> <p>将 Vue.js 添加到项目中主要有四种方式：</p> <ol><li>在页面上以 <a href="#cdn">CDN 包</a>的形式导入。</li> <li>下载 JavaScript 文件并<a href="#%E4%B8%8B%E8%BD%BD%E5%B9%B6%E8%87%AA%E6%89%98%E7%AE%A1">自行托管</a>。</li> <li>使用 <a href="#npm">npm</a> 安装它。</li> <li>使用官方的 <a href="#%E5%91%BD%E4%BB%A4%E8%A1%8C%E5%B7%A5%E5%85%B7-cli">CLI</a> 来构建一个项目，它为现代前端工作流程提供了功能齐备的构建设置 (例如，热重载、保存时的提示等等)。</li></ol> <h2 id="发布版本说明"><a href="#发布版本说明" class="header-anchor">#</a> 发布版本说明</h2> <p>最新版本：<img src="https://img.shields.io/npm/v/vue/next.svg" alt="npm"></p> <p>每个版本的详细发布说明都可以在 <a href="https://github.com/vuejs/vue-next/blob/master/CHANGELOG.md" target="_blank" rel="noopener noreferrer">GitHub<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> 上找到。</p> <h2 id="vue-devtools"><a href="#vue-devtools" class="header-anchor">#</a> Vue Devtools</h2> <blockquote><p>目前处于测试阶段 - Vuex 和 Router 的集成仍在进行中。</p></blockquote> <section class="video-lesson"><a href="https://vueschool.io/lessons/using-vue-dev-tools-with-vuejs-3?friend=vuejs" target="_blank" rel="sponsored noopener" title="在 Vue School 学习如何安装">通过 Vue School 的免费课程学习如何安装和使用 Vue Devtools</a></section> <p>在使用 Vue 时，我们推荐在你的浏览器上安装 <a href="https://github.com/vuejs/vue-devtools#vue-devtools" target="_blank" rel="noopener noreferrer">Vue Devtools<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>，它允许你在一个更友好的界面中审查和调试 Vue 应用。</p> <p><a href="https://chrome.google.com/webstore/detail/vuejs-devtools/ljjemllljcmogpfapbkkighbhhppjdbg" target="_blank" rel="noopener noreferrer">获取 Chrome 扩展程序<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></p> <p><a href="https://addons.mozilla.org/en-US/firefox/addon/vue-js-devtools/" target="_blank" rel="noopener noreferrer">获取 Firefox 附加组件<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></p> <p><a href="https://github.com/vuejs/vue-devtools/blob/dev/packages/shell-electron/README.md" target="_blank" rel="noopener noreferrer">获取独立的 Electron 应用程序<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></p> <h2 id="cdn"><a href="#cdn" class="header-anchor">#</a> CDN</h2> <p>对于制作原型或学习，你可以这样使用最新版本：</p> <div class="language-html line-numbers-mode"><pre class="language-html"><code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>script</span> <span class="token attr-name">src</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>https://unpkg.com/vue@next<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span><span class="token script"></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>script</span><span class="token punctuation">&gt;</span></span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>对于生产环境，我们推荐链接到一个明确的版本号和构建文件，以避免新版本造成的不可预期的破坏。</p> <h2 id="下载并自托管"><a href="#下载并自托管" class="header-anchor">#</a> 下载并自托管</h2> <p>如果你想避免使用构建工具，但又无法在生产环境使用 CDN，那么你可以下载相关 <code>.js</code> 文件并自行托管在你的服务器上。然后你可以通过 <code>&lt;script&gt;</code> 标签引入，与使用 CDN 的方法类似。</p> <p>这些文件可以在 <a href="https://unpkg.com/browse/vue@next/dist/" target="_blank" rel="noopener noreferrer">unpkg<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> 或者 <a href="https://cdn.jsdelivr.net/npm/vue@next/dist/" target="_blank" rel="noopener noreferrer">jsDelivr<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> 这些 CDN 上浏览和下载。各种不同文件将在<a href="#%E5%AF%B9%E4%B8%8D%E5%90%8C%E6%9E%84%E5%BB%BA%E7%89%88%E6%9C%AC%E7%9A%84%E8%A7%A3%E9%87%8A">以后解释</a>，但你通常需要同时下载开发环境构建版本以及生产环境构建版本。</p> <h2 id="npm"><a href="#npm" class="header-anchor">#</a> npm</h2> <p>在用 Vue 构建大型应用时推荐使用 npm 安装<sup><a href="#footnote-1">[1]</a></sup> 。npm 能很好地和诸如 <a href="https://webpack.js.org/" target="_blank" rel="noopener noreferrer">webpack<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> 或 <a href="https://rollupjs.org/" target="_blank" rel="noopener noreferrer">Rollup<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> 模块打包器配合使用。</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token comment"># 最新稳定版</span>
$ <span class="token function">npm</span> <span class="token function">install</span> vue@next
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p>Vue 还提供了编写<a href="/vue3/guide/single-file-component.html">单文件组件</a>的配套工具。如果你想使用单文件组件，那么你还需要安装 <code>@vue/compiler-sfc</code>：</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>$ <span class="token function">npm</span> <span class="token function">install</span> -D @vue/compiler-sfc
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>如果你是从 Vue 2 过渡而来的，请注意 <code>@vue/compiler-sfc</code> 替换掉了 <code>vue-template-compiler</code></p> <p>除了 <code>@vue/compiler-sfc</code> 之外，你还需要为已选择的打包工具选择一个配套的单文件组件 loader 或 plugin。更多信息请查阅<a href="/vue3/guide/single-file-component.html">单文件组件文档</a>。</p> <p>大多数情况下，我们更倾向于使用 Vue CLI 来创建一个配置最小化的 webpack 构建版本。</p> <h2 id="命令行工具-cli"><a href="#命令行工具-cli" class="header-anchor">#</a> 命令行工具 (CLI)</h2> <p>Vue 提供了一个<a href="https://cli.vuejs.org/zh/" target="_blank" rel="noopener noreferrer">官方的 CLI<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>，为单页面应用 (SPA) 快速搭建繁杂的脚手架。它为现代前端工作流提供了功能齐备的构建设置。只需要几分钟的时间就可以运行起来并带有热重载、保存时 lint 校验，以及生产环境可用的构建版本。更多详情可查阅 <a href="https://cli.vuejs.org/zh/" target="_blank" rel="noopener noreferrer">Vue CLI 的文档<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>。</p> <div class="custom-block tip"><p class="custom-block-title">TIP</p> <p>CLI 工具假定用户对 Node.js 和相关构建工具有一定程度的了解。如果你是新手，我们强烈建议先在不用构建工具的情况下通读<a href="/vue3/guide/introduction.html">指南</a>，在熟悉 Vue 本身之后再使用 CLI。</p></div> <p>对于 Vue 3，你应该使用 <code>npm</code> 上可用的 Vue CLI v4.5 作为 <code>@vue/cli</code>。要升级，你应该需要全局重新安装最新版本的 <code>@vue/cli</code>：</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token function">yarn</span> global <span class="token function">add</span> @vue/cli
<span class="token comment"># 或</span>
<span class="token function">npm</span> <span class="token function">install</span> -g @vue/cli
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p>然后在 Vue 项目中运行：</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>vue upgrade --next
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h2 id="vite"><a href="#vite" class="header-anchor">#</a> Vite</h2> <p><a href="https://cn.vitejs.dev/" target="_blank" rel="noopener noreferrer">Vite<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> 是一个 web 开发构建工具，由于其原生 ES 模块导入方式，可以实现闪电般的冷服务器启动。</p> <p>通过在终端中运行以下命令，可以使用 Vite 快速构建 Vue 项目。</p> <p>使用 npm：</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token comment"># npm 6.x</span>
$ <span class="token function">npm</span> init vite@latest <span class="token operator">&lt;</span>project-name<span class="token operator">&gt;</span> --template vue

<span class="token comment"># npm 7+，需要加上额外的双短横线</span>
$ <span class="token function">npm</span> init vite@latest <span class="token operator">&lt;</span>project-name<span class="token operator">&gt;</span> -- --template vue

$ <span class="token builtin class-name">cd</span> <span class="token operator">&lt;</span>project-name<span class="token operator">&gt;</span>
$ <span class="token function">npm</span> <span class="token function">install</span>
$ <span class="token function">npm</span> run dev
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br></div></div><p>或者 yarn：</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>$ <span class="token function">yarn</span> create vite <span class="token operator">&lt;</span>project-name<span class="token operator">&gt;</span> --template vue
$ <span class="token builtin class-name">cd</span> <span class="token operator">&lt;</span>project-name<span class="token operator">&gt;</span>
$ <span class="token function">yarn</span>
$ <span class="token function">yarn</span> dev
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><h2 id="对不同构建版本的解释"><a href="#对不同构建版本的解释" class="header-anchor">#</a> 对不同构建版本的解释</h2> <p>在 <a href="https://cdn.jsdelivr.net/npm/vue@3.0.2/dist/" target="_blank" rel="noopener noreferrer">npm 包的 dist/ 目录<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>你将会找到很多不同的 Vue.js 构建版本。下面是一个概述，根据不同的使用情况，应该使用哪个 <code>dist</code> 文件：</p> <h3 id="使用-cdn-或没有构建工具"><a href="#使用-cdn-或没有构建工具" class="header-anchor">#</a> 使用 CDN 或没有构建工具</h3> <h4 id="vue-runtime-global-prod-js"><a href="#vue-runtime-global-prod-js" class="header-anchor">#</a> <code>vue(.runtime).global(.prod).js</code>：</h4> <ul><li>若要通过浏览器中的 <code>&lt;script src=&quot;...&quot;&gt;</code> 直接使用，则暴露 Vue 全局。</li> <li>浏览器内模板编译：
<ul><li><code>vue.global.js</code> 是包含编译器和运行时的“完整”构建版本，因此它支持动态编译模板。</li> <li><code>vue.runtime.global.js</code> 只包含运行时，并且需要在构建步骤期间预编译模板。</li></ul></li> <li>内联所有 Vue 核心内部包——即：它是一个单独的文件，不依赖于其他文件。这意味着你必须导入此文件和此文件中的所有内容，以确保获得相同的代码实例。</li> <li>包含硬编码的 prod/dev 分支，并且 prod 构建版本是预先压缩过的。将 <code>*.prod.js</code> 文件用于生产环境。</li></ul> <div class="custom-block tip"><p class="custom-block-title">提示</p> <p>全局打包不是 <a href="https://github.com/umdjs/umd" target="_blank" rel="noopener noreferrer">UMD<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> 构建的，它们被打包成 <a href="https://developer.mozilla.org/en-US/docs/Glossary/IIFE" target="_blank" rel="noopener noreferrer">IIFEs<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>，并且仅用于通过 <code>&lt;script src=&quot;...&quot;&gt;</code> 直接使用。</p></div> <h4 id="vue-runtime-esm-browser-prod-js"><a href="#vue-runtime-esm-browser-prod-js" class="header-anchor">#</a> <code>vue(.runtime).esm-browser(.prod).js</code>：</h4> <ul><li>用于通过原生 ES 模块导入使用 (在浏览器中通过 <code>&lt;script type=&quot;module&quot;&gt;</code> 来使用)。</li> <li>与全局构建版本共享相同的运行时编译、依赖内联和硬编码的 prod/dev 行为。</li></ul> <h3 id="使用构建工具"><a href="#使用构建工具" class="header-anchor">#</a> 使用构建工具</h3> <h4 id="vue-runtime-esm-bundler-js"><a href="#vue-runtime-esm-bundler-js" class="header-anchor">#</a> <code>vue(.runtime).esm-bundler.js</code>：</h4> <ul><li>用于 <code>webpack</code>，<code>rollup</code> 和 <code>parcel</code> 等构建工具。</li> <li>留下 prod/dev 分支的 <code>process.env.NODE_ENV</code> 守卫语句 (必须由构建工具替换)。</li> <li>不提供压缩版本 (打包后与其余代码一起压缩)。</li> <li>import 依赖 (例如：<code>@vue/runtime-core</code>，<code>@vue/runtime-compiler</code>)
<ul><li>导入的依赖项也是 esm bundler 构建版本，并将依次导入其依赖项 (例如：@vue/runtime-core imports @vue/reactivity)。</li> <li>这意味着你<strong>可以</strong>单独安装/导入这些依赖，而不会导致这些依赖项的不同实例，但你必须确保它们都为同一版本。</li></ul></li> <li>浏览器内模板编译：
<ul><li><code>vue.runtime.esm-bundler.js</code> <strong>(默认)</strong> 仅运行时，并要求所有模板都要预先编译。这是构建工具的默认入口 (通过 <code>package.json</code> 中的 module 字段)，因为在使用构建工具时，模板通常是预先编译的 (例如：在 <code>*.vue</code> 文件中)。</li> <li><code>vue.esm-bundler.js</code> 包含运行时编译器。如果你使用了一个构建工具，但仍然想要运行时的模板编译 (例如，DOM 内 模板或通过内联 JavaScript 字符串的模板)，请使用这个文件。你需要配置你的构建工具，将 vue 设置为这个文件。</li></ul></li></ul> <h3 id="对于服务端渲染"><a href="#对于服务端渲染" class="header-anchor">#</a> 对于服务端渲染</h3> <h4 id="vue-cjs-prod-js"><a href="#vue-cjs-prod-js" class="header-anchor">#</a> <code>vue.cjs(.prod).js</code>：</h4> <ul><li>通过 <code>require()</code> 在 Node.js 服务器端渲染使用。</li> <li>如果你将应用程序与带有 <code>target: 'node'</code> 的 webpack 打包在一起，并正确地将 <code>vue</code> 外部化，则将加载此文件。</li> <li>dev/prod 文件是预构建的，但是会根据 <code>process.env.NODE_ENV</code> 自动加载相应的文件。</li></ul> <h2 id="运行时-编译器-vs-仅运行时"><a href="#运行时-编译器-vs-仅运行时" class="header-anchor">#</a> 运行时 + 编译器 vs. 仅运行时</h2> <p>如果需要在客户端上编译模板 (即：将字符串传递给 template 选项，或者使用元素的 DOM 内 HTML 作为模板挂载到元素)，你将需要编译器，因此需要完整的构建版本：</p> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token comment">// 需要编译器</span>
Vue<span class="token punctuation">.</span><span class="token function">createApp</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
  template<span class="token operator">:</span> <span class="token string">'<span class="language-html"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span><span class="token punctuation">&gt;</span></span><span class="token interpolation"><span class="token punctuation">{{</span><span class="token inline-js language-js"> hi </span><span class="token punctuation">}}</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span></span>'</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span>

<span class="token comment">// 不需要</span>
Vue<span class="token punctuation">.</span><span class="token function">createApp</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
  <span class="token function">render</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> Vue<span class="token punctuation">.</span><span class="token function">h</span><span class="token punctuation">(</span><span class="token string">'div'</span><span class="token punctuation">,</span> <span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token keyword">this</span><span class="token punctuation">.</span>hi<span class="token punctuation">)</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br></div></div><p>当使用 <code>vue-loader</code> 时，<code>*.vue</code> 文件中的模板会在构建时预编译为 JavaScript，在最终的捆绑包中并不需要编译器，因此可以只使用运行时构建版本。</p> <p><small><strong>译者注</strong><br> <a id="footnote-1"></a>[1] 对于中国大陆用户，建议将 NPM 源设置为<a href="https://npmmirror.com/" target="_blank" rel="noopener noreferrer">国内的镜像<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>，可以大幅提升安装速度。</small></p></div> <footer class="page-edit" data-v-007274aa><div class="container" data-v-007274aa><p data-v-007274aa><span class="edit-link" data-v-007274aa>
         发现了错误或者想要为文档做贡献？
          <a href="https://github.com/vuejs/docs-next-zh-cn/edit/master/src/guide/installation.md" target="_blank" rel="noopener noreferrer" data-v-007274aa>
            在 GitHub 上编辑此页
            <span data-v-007274aa><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></span> <!----></p></div></footer> <div class="page-nav"><p class="inner"><!----> <span class="next"><a href="/vue3/guide/introduction.html">介绍</a>
      →
    </span></p></div> <div class="bsa-cpc-wrapper"><div class="bsa-cpc"></div></div> </main></div><div class="global-ui"><!----></div></div>
    <script src="/vue3/assets/js/app.9f011487.js" defer></script><script src="/vue3/assets/js/11.bea13863.js" defer></script><script src="/vue3/assets/js/116.5836841c.js" defer></script><script src="/vue3/assets/js/25.3a155505.js" defer></script><script src="/vue3/assets/js/23.f23a1976.js" defer></script>
  </body>
</html>
